package org.dyz.banana.platform.sample.eurakaclient2.controller;

import org.dyz.banana.platform.sample.eurakaclient2.service.FeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;

@RestController
public class FeignController {

	@Autowired
	FeignService feignService;
	
	@GetMapping("/sample2/getData")
	@HystrixCommand(fallbackMethod = "getDataFallback",commandProperties = {
		    // 超过3s同样会服务降级、抛出异常也会服务降级
		    @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "3000")
		  })
	public String getData(@RequestParam("name")String name) {
		return feignService.getData(name);
	}
	
	
	public String getDataFallback(String name) {
		return "服务降级了";
	}
	
	
	@GetMapping("/sample2/getData/{name}")
	public String getData2(@PathVariable("name")String name) {
		return feignService.getData2(name);
	}
	
	@PostMapping("/sample2/setData")
	public String setData(@RequestParam("name")String name) {
		return feignService.setData(name);
	}
	
	@PostMapping("/sample2/setData/{name}")
	public String setData2(@PathVariable("name")String name) {
		return feignService.setData2(name);
	}
}
